package com.lzp.copyui.design

import android.os.Bundle
import com.base.BaseActivity
import com.google.android.material.shape.CornerFamily
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel
import com.google.android.material.shape.ShapePath
import com.google.android.material.shape.TriangleEdgeTreatment
import com.lzp.copyui.R
import com.view.ViewHelper
import kotlinx.android.synthetic.main.shape_view_activity.*

/**
 * @describe:
 * @Author: lixiaopeng
 * @Date: 2020/11/10
 */
class ShapeViewActivity : BaseActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.shape_view_activity)
    }

    private val bgColor = 0xffe60012.toInt()
    private val strokeColor = 0xffa0a0a0.toInt()

    override fun initView() {
        super.initView()

        view1.background = ViewHelper.createShapeDrawable(30f, bgColor)
        view2.background = ViewHelper.createShapeDrawable(30f, bgColor, strokeColor, 20f)
        view3.background = ViewHelper.createShapeDrawable(bgColor, 30f, 30f, 0f, 0f)

        view4.background = MaterialShapeDrawable(
                ShapeAppearanceModel.builder()
                        .setAllCorners(CornerFamily.ROUNDED, 30f)
                        .setAllEdges(TriangleEdgeTreatment(16f, true))
                        .build()
        ).apply {
            setTint(bgColor)
            setStroke(10f, this@ShapeViewActivity.strokeColor)
        }

        view5.background = MaterialShapeDrawable(
                ShapeAppearanceModel.builder()
                        .setAllCorners(CornerFamily.ROUNDED, 30f)
                        .setRightEdge(object : TriangleEdgeTreatment(26f, false) {
                            override fun getEdgePath(length: Float, center: Float, interpolation: Float, shapePath: ShapePath) {
                                super.getEdgePath(length, 26f, interpolation, shapePath)
                            }
                        })
                        .build()
        ).apply {
            setTint(0x00000000)
            setStroke(3f, this@ShapeViewActivity.strokeColor)
        }

        view6.background = ViewHelper.createShapeDrawable(bgColor, 30f, 0f, 0f, 30f)
        view7.background = ViewHelper.createShapeDrawable(bgColor, strokeColor, 10f, 30f, 30f, 0f, 30f)
    }
}